package com.sikao.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cnzhizi.wheelpop.model.OneModel;
import com.cnzhizi.wheelpop.model.ThreeModel;
import com.cnzhizi.wheelpop.model.TwoModel;
import com.cnzhizi.wheelpop.ui.SkmDatePickerPopup;
import com.cnzhizi.wheelpop.ui.SkmModiPopup;
import com.sikao.app.R;
import com.sikao.app.bean.AddGoodsParamBean;
import com.sikao.app.bean.AddInviteOneBean;
import com.sikao.app.bean.AddInviteOneSubmitBean;
import com.sikao.app.bean.AreaBean;
import com.sikao.app.bean.AreaSubmitBean;
import com.sikao.app.bean.CalculateCreditBean;
import com.sikao.app.bean.CalculateCreditSubmitBean;
import com.sikao.app.bean.CalculateMarginBean;
import com.sikao.app.bean.CalculateMarginSubmitBean;
import com.sikao.app.bean.GoodsCategoryBeanTest;
import com.sikao.app.bean.GoodsCategorySubmitBean;
import com.sikao.app.bean.OwnInviteDetailBean;
import com.sikao.app.bean.OwnInviteDetailSubmitBean;
import com.sikao.app.dao.AddGoodsParamModel;
import com.sikao.app.dao.AddInviteOneModel;
import com.sikao.app.dao.AreaBeanModel;
import com.sikao.app.dao.CalculateCreditModel;
import com.sikao.app.dao.CalculateMarginModel;
import com.sikao.app.dao.GoodsCategoryModelTest;
import com.sikao.app.dao.OwnInviteDetailModel;
import com.sikao.app.net.OnNetBackListener;
import com.sikao.app.ui.base.BaseActivity;
import com.sikao.app.utils.ConstantClass;
import com.sikao.app.utils.JSONUtil;
import com.sikao.app.utils.TimeUtil;
import com.sikao.app.utils.Utils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 买家中心发布招标模块
 */
public class ReleaseTenderActivity extends BaseActivity implements View.OnClickListener {

	public static final int PAY_REQUEST_CODE = 10002;//保证金付款请求的code
	public static final int PAY_RESULT_CODE = 100020;//保证金付款正常返回的code
	public static final int STEP_TWO_REQUEST_CODE = 10004;//添加添加附加信息 第二步请求的code
	public static final int STEP_TWO_RESULT_CODE = 100040;//添加添加附加信息 第二步正常返回的code
	private TextView titleTv;
	private TextView title_right_tv;
	private ImageView backIv;

	//商品分类
	private String classifyId;
	//货品名称
	private String goodsTitle;
	//产品品牌
	private String goodsProductCode = "";
	//单位
	private String goodsUnit;
	//数量
	private String goodsNumber;
	//发布类型
	private String goodsPushTypeId;
	//招标单价
	private String goodsPrice;
	//是否拆分出售
	private int inviteIssplit = 1;
	//最小供应量
	private int goodsLeastNumber = 0;
	//最小供应量单位
	// private String goodsLeastNumberUnit;
	//阶梯价格的id集合
	private String stepPrice;
	//起拍价 (总价)
	private String goodsTotalPrice;
	//最低加价幅度
	private double goodsLeastAdd;
	//一口价stepPrice
	private double goodsFixedPrice;
	//支付方式
	private int goodsPaytype;
	//分期比例
	private double scaleOne;
	private double scaleTwo;
	private double scaleThree;
	//挂单方式
	private int goodsPublishTypeId;

	//定向用户
	private String goodsToUser;
	//交割地
	private String deliveryArea;
	private String province;
	private String city;
	private String county;
	//交割方式
	private String goodsDeliveryType;
	//开始日期
	private String startTime;
	//结束日期
	private String endTime;
	//备注
	private String remark;
	//是否启用阶梯价格
	private boolean isUseStepPrice = false;
	//是否启用仓单图片
	private boolean isUsestorePic = false;
	//参数
	private AddGoodsParamBean addGoodsParamBean;
	//添加商品第一步提交的信息
	//private AddGoodsStepOneSubmitBean addInviteOneSubmitBean = new AddGoodsStepOneSubmitBean();
	private AddInviteOneSubmitBean addInviteOneSubmitBean = new AddInviteOneSubmitBean();
	private int releaseInviteState = 1;//1发布进入，2返回进入，3详情进入
	private String inviteId;

	private String catId = "";

	OwnInviteDetailBean ownInviteDetailBean;

	//分类
	private RelativeLayout rlReleaseTenderClassify;
	private TextView tvReleaseTenderClassify;
	//名称
	private EditText etReleaseTenderTitle;
	//品牌
	private EditText etReleaseTenderProductCode;
	//是否拆分
	private RelativeLayout rlReleaseTenderIssplit;
	private TextView tvReleaseTenderIssplit;
	//单价
	private EditText etReleaseTenderPrice;
	//单位
	private TextView tvReleaseTenderUnit;
	//数量
	private EditText etReleaseTenderNumber;
	private TextView tvReleaseTenderLeastNumberUnit;
	//最小供应量
	private EditText etReleaseTenderLeastNumber;
	private LinearLayout llReleaseTenderLeastNumber;
	//投标保证金
	private EditText etReleaseTenderMarginScale;
	//支付方式
	private RelativeLayout rlReleaseTenderPaytype;
	private TextView tvReleasePaytype;
	//分期
	private LinearLayout llReleaseTenderPaytypeForInstallment;
	private EditText etScaleOne;
	private EditText etScaleTwo;
	private EditText etScaleThree;
	//挂单方式
	private RelativeLayout rlReleaseTenderPublishType;
	private TextView tvReleaseTenderPublishType;
	//保证金
	private RelativeLayout rlReleaseTenderSellMargin;
	private TextView tvCash;
	private TextView tvMargin;
	//信誉
	private RelativeLayout rlReleaseTenderSellCredit;
	private TextView tvOwncredit;
	private TextView tvCredit;
	//交割地
	private RelativeLayout rlReleaseTenderDeliveryArea;
	private TextView tvReleaseTenderDeliveryArea;
	//交割方式
	private RelativeLayout rlReleaseTenderDeliveryType;
	private TextView tvReleaseTenderDeliveryType;
	//开始时间
	private RelativeLayout rlReleaseTenderStartTime;
	private TextView tvReleaseTenderStartTime;
	//结束时间
	private RelativeLayout rlReleaseTenderEndTime;
	private TextView tvReleaseTenderEndTime;
	private EditText etReleaseTenderRemark;

	private String payPassword="";
	private String inviteStatus="";
	public static ReleaseTenderActivity releaseTenderActivity;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_release_tender);
		super.onCreate(savedInstanceState);
		releaseTenderActivity=this;
	}

	@Override
	protected void initData() {
		Intent intent = getIntent();
		releaseInviteState = intent.getIntExtra("releaseInviteState", 1);
		if (releaseInviteState == 3) {
			inviteId = intent.getStringExtra("inviteId");
			inviteStatus = intent.getStringExtra("inviteStatus");
			Utils.showLog("=====inviteId:" + inviteId);
			OwnInviteDetailSubmitBean ownInviteDetailSubmitBean = new OwnInviteDetailSubmitBean();
			ownInviteDetailSubmitBean.setInviteId(inviteId + "");
			new OwnInviteDetailModel(this, new OnNetBackListener<OwnInviteDetailBean>() {
				@Override
				public void netBack(OwnInviteDetailBean data) {
					if (data == null) {
						Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							ownInviteDetailBean = data;
							initViewDataForDetail();
						} else {
							Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}

			}).request(JSONUtil.toJSON(ownInviteDetailSubmitBean), true);

		}
	}

	/**
	 * 从招标详情进入的 给界面赋值
	 */
	private void initViewDataForDetail() {
		//招标状态
		inviteStatus = ownInviteDetailBean.getRes().getStatus();
		//招标分类id
		catId = ownInviteDetailBean.getRes().getCat_id();
		//招标id
		inviteId = ownInviteDetailBean.getRes().getId();

		tvReleaseTenderClassify.setText(ownInviteDetailBean.getRes().getCat_name());
		etReleaseTenderTitle.setText(ownInviteDetailBean.getRes().getTitle());
		etReleaseTenderProductCode.setText(ownInviteDetailBean.getRes().getProduct_code());
		etReleaseTenderNumber.setText(ownInviteDetailBean.getRes().getNumber());
		tvReleaseTenderLeastNumberUnit.setText("("+ownInviteDetailBean.getRes().getUnit()+")：");
		tvReleaseTenderUnit.setText("("+ownInviteDetailBean.getRes().getUnit()+")：");
		goodsUnit = ownInviteDetailBean.getRes().getUnit();

		//单价
		etReleaseTenderPrice.setText(ownInviteDetailBean.getRes().getPrice());
		//投标保证金
		etReleaseTenderMarginScale.setText(ownInviteDetailBean.getRes().getMargin_scale());

		//是否拆分出售
		inviteIssplit = Integer.parseInt(ownInviteDetailBean.getRes().getIs_ported());//是否可拆分 0不可 1可拆分
		tvReleaseTenderIssplit.setText(ownInviteDetailBean.getRes().getIs_ported_str());

		if (inviteIssplit == 0) {//不可拆分
			llReleaseTenderLeastNumber.setVisibility(View.GONE);
			etReleaseTenderLeastNumber.setText("0");
		} else {
			llReleaseTenderLeastNumber.setVisibility(View.VISIBLE);
			etReleaseTenderLeastNumber.setText(ownInviteDetailBean.getRes().getLeast_number());
		}

		//支付方式
		tvReleasePaytype.setText(ownInviteDetailBean.getRes().getPay_type_str());
		String[] payScaleData = ownInviteDetailBean.getRes().getPay_scale().split(",");

		int payTypeId = Integer.parseInt(ownInviteDetailBean.getRes().getPay_type());

     if (payScaleData==null||payScaleData.length<3) {
		Utils.showToast("分期数据异常！");
	 }else{
		 switch (payTypeId) {
			 case 1://全款
				 //隐藏分期ui
				 llReleaseTenderPaytypeForInstallment.setVisibility(View.GONE);
				 //设置分期的textview的值
				 etScaleOne.setText(payScaleData[0]);
				 etScaleTwo.setText(payScaleData[1]);
				 etScaleThree.setText(payScaleData[2]);
				 break;
			 case 2://分期
				 //显示分期ui
				 llReleaseTenderPaytypeForInstallment.setVisibility(View.VISIBLE);
				 //设置分期的textview的值
				 etScaleOne.setText(payScaleData[0]);
				 etScaleTwo.setText(payScaleData[1]);
				 etScaleThree.setText(payScaleData[2]);
				 break;
			 case 3://货到付款
				 //隐藏分期ui
				 llReleaseTenderPaytypeForInstallment.setVisibility(View.GONE);
				 //设置分期的textview的值
				 etScaleOne.setText(payScaleData[0]);
				 etScaleTwo.setText(payScaleData[1]);
				 etScaleThree.setText(payScaleData[2]);
				 break;
		 }
	 }
		//挂单方式
		tvReleaseTenderPublishType.setText(ownInviteDetailBean.getRes().getPublish_type_str());
		int publishTypeId = Integer.parseInt(ownInviteDetailBean.getRes().getPublish_type());

		switch (publishTypeId) {
			case 2://2保证金挂单
				rlReleaseTenderSellMargin.setVisibility(View.VISIBLE);
				rlReleaseTenderSellCredit.setVisibility(View.GONE);
				//计算保证金
				calculateMarginAndCredit();

				break;
			case 3://3信誉挂单
				rlReleaseTenderSellMargin.setVisibility(View.GONE);
				rlReleaseTenderSellCredit.setVisibility(View.VISIBLE);
				//计算信誉值
				calculateMarginAndCredit();
				break;
		}

		//所在地
		tvReleaseTenderDeliveryArea.setText(ownInviteDetailBean.getRes().getDelivery_area());
		tvReleaseTenderDeliveryType.setText(ownInviteDetailBean.getRes().getDelivery_type_str());
		tvReleaseTenderStartTime.setText(TimeUtil.timeStampToTime(ownInviteDetailBean.getRes().getStart_time(),TimeUtil.fotmatString2));
		tvReleaseTenderEndTime.setText(TimeUtil.timeStampToTime(ownInviteDetailBean.getRes().getEnd_time(),TimeUtil.fotmatString2));
		etReleaseTenderRemark.setText(ownInviteDetailBean.getRes().getRemark());

	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		title_right_tv = (TextView) findViewById(R.id.title_right_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);

		rlReleaseTenderClassify = (RelativeLayout) findViewById(R.id.rl_release_tender_classify);
		tvReleaseTenderClassify = (TextView) findViewById(R.id.tv_release_tender_classify);
		etReleaseTenderTitle = (EditText) findViewById(R.id.et_release_tender_title);
		etReleaseTenderProductCode = (EditText) findViewById(R.id.et_release_tender_product_code);
		rlReleaseTenderIssplit = (RelativeLayout) findViewById(R.id.rl_release_tender_issplit);
		tvReleaseTenderIssplit = (TextView) findViewById(R.id.tv_release_tender_issplit);
		etReleaseTenderPrice = (EditText) findViewById(R.id.et_release_tender_price);
		tvReleaseTenderUnit = (TextView) findViewById(R.id.tv_release_tender_unit);
		etReleaseTenderNumber = (EditText) findViewById(R.id.et_release_tender_number);
		tvReleaseTenderLeastNumberUnit = (TextView) findViewById(R.id.tv_release_tender_least_number_unit);
		etReleaseTenderLeastNumber = (EditText) findViewById(R.id.et_release_tender_least_number);
		etReleaseTenderMarginScale = (EditText) findViewById(R.id.et_release_tender_margin_scale);
		rlReleaseTenderPaytype = (RelativeLayout) findViewById(R.id.rl_release_tender_paytype);
		tvReleasePaytype = (TextView) findViewById(R.id.tv_release_paytype);
		llReleaseTenderPaytypeForInstallment = (LinearLayout) findViewById(R.id.ll_release_tender_paytype_for_installment);
		etScaleOne = (EditText) findViewById(R.id.et_scale_one);
		etScaleTwo = (EditText) findViewById(R.id.et_scale_two);
		etScaleThree = (EditText) findViewById(R.id.et_scale_three);
		rlReleaseTenderPublishType = (RelativeLayout) findViewById(R.id.rl_release_tender_publish_type);
		tvReleaseTenderPublishType = (TextView) findViewById(R.id.tv_release_tender_publish_type);
		rlReleaseTenderSellMargin = (RelativeLayout) findViewById(R.id.rl_release_tender_sell_margin);
		tvCash = (TextView) findViewById(R.id.tv_cash);
		tvMargin = (TextView) findViewById(R.id.tv_margin);
		rlReleaseTenderSellCredit = (RelativeLayout) findViewById(R.id.rl_release_tender_sell_credit);
		tvOwncredit = (TextView) findViewById(R.id.tv_owncredit);
		tvCredit = (TextView) findViewById(R.id.tv_credit);
		llReleaseTenderLeastNumber = (LinearLayout) findViewById(R.id.ll_release_tender_least_number);
		rlReleaseTenderDeliveryArea = (RelativeLayout) findViewById(R.id.rl_release_tender_delivery_area);
		tvReleaseTenderDeliveryArea = (TextView) findViewById(R.id.tv_release_tender_delivery_area);
		rlReleaseTenderDeliveryType = (RelativeLayout) findViewById(R.id.rl_release_tender_delivery_type);
		tvReleaseTenderDeliveryType = (TextView) findViewById(R.id.tv_release_tender_delivery_type);
		rlReleaseTenderStartTime = (RelativeLayout) findViewById(R.id.rl_release_tender_start_time);
		tvReleaseTenderStartTime = (TextView) findViewById(R.id.tv_release_tender_start_time);
		rlReleaseTenderEndTime = (RelativeLayout) findViewById(R.id.rl_release_tender_end_time);
		tvReleaseTenderEndTime = (TextView) findViewById(R.id.tv_release_tender_end_time);
		etReleaseTenderRemark = (EditText) findViewById(R.id.et_release_tender_remark);
	}

	@Override
	protected void initListener() {

		backIv.setOnClickListener(this);
		title_right_tv.setOnClickListener(this);//下一步
		if (releaseInviteState == 1) {
			//分类
			rlReleaseTenderClassify.setOnClickListener(this);
			//是否拆分
			rlReleaseTenderIssplit.setOnClickListener(this);
			//支付方式
			rlReleaseTenderPaytype.setOnClickListener(this);
			//挂单方式
			rlReleaseTenderPublishType.setOnClickListener(this);
			//交割方式
			rlReleaseTenderDeliveryType.setOnClickListener(this);
			//所在地
			rlReleaseTenderDeliveryArea.setOnClickListener(this);
			//开始时间
			rlReleaseTenderStartTime.setOnClickListener(this);
			//结束时间
			rlReleaseTenderEndTime.setOnClickListener(this);
			etReleaseTenderNumber.addTextChangedListener(new TextWatcher() {
				@Override
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {

				}

				@Override
				public void onTextChanged(CharSequence s, int start, int before, int count) {

				}

				@Override
				public void afterTextChanged(Editable s) {

					calculateMarginAndCredit();

				}
			});
			etReleaseTenderPrice.addTextChangedListener(new TextWatcher() {
				@Override
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {

				}

				@Override
				public void onTextChanged(CharSequence s, int start, int before, int count) {

				}

				@Override
				public void afterTextChanged(Editable s) {

					calculateMarginAndCredit();
				}
			});
		} else {
			setEnable(false);
		}
	}

	private void setEnable(boolean enable) {
		//分类
		rlReleaseTenderClassify.setEnabled(enable);
		//是否拆分
		rlReleaseTenderIssplit.setEnabled(enable);
		//支付方式
		rlReleaseTenderPaytype.setEnabled(enable);
		//挂单方式
		rlReleaseTenderPublishType.setEnabled(enable);
		//交割方式
		rlReleaseTenderDeliveryType.setEnabled(enable);
		//所在地
		rlReleaseTenderDeliveryArea.setEnabled(enable);
		//开始时间
		rlReleaseTenderStartTime.setEnabled(enable);
		//结束时间
		rlReleaseTenderEndTime.setEnabled(enable);

		etReleaseTenderLeastNumber.setEnabled(enable);
		etReleaseTenderNumber.setEnabled(enable);
		etReleaseTenderPrice.setEnabled(enable);
		etReleaseTenderProductCode.setEnabled(enable);
		etReleaseTenderRemark.setEnabled(enable);
		etReleaseTenderTitle.setEnabled(enable);
		etScaleOne.setEnabled(enable);
		etScaleTwo.setEnabled(enable);
		etScaleThree.setEnabled(enable);
		etReleaseTenderMarginScale.setEnabled(enable);
	}

	@Override
	protected void init() {
		titleTv.setText("发布招标");
		backIv.setVisibility(View.VISIBLE);
		title_right_tv.setVisibility(View.VISIBLE);
		title_right_tv.setText("下一步");
		//加载页面的时候 从后台获取参数
		if (releaseInviteState == 1) {//发布招标进入的
			new AddGoodsParamModel(this, new OnNetBackListener<AddGoodsParamBean>() {
				@Override
				public void netBack(AddGoodsParamBean data) {
					if (data == null) {
						Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							addGoodsParamBean = data;
							initViewData();
						} else {
							Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request("{}", true);
		} else if (releaseInviteState == 2) {//返回进入的

		} else if (releaseInviteState == 3) {//点击详情进入的

		}
	}

	/**
	 * id : 0
	 * value : 否
	 */

	private List<AddGoodsParamBean.ResBean.IsPortedBean> isPortedList;
	/**
	 * id : 1
	 * value : 全款
	 */

	/**
	 * 发布类型
	 * id : 0
	 * value : 商城
	 */

	private List<AddGoodsParamBean.ResBean.AddToBean> addToList;

	private List<AddGoodsParamBean.ResBean.PayTypeBean> payTypeList;
	/**
	 * id : 1
	 * value : 仓单挂单
	 */

	//private List<AddGoodsParamBean.ResBean.PublishTypeBean> publishTypeList;
	private List<AddGoodsParamBean.ResBean.InvitePublishTypeBean> publishTypeList;
	/**
	 * id : 1
	 * value : 买家自提
	 */

	private List<AddGoodsParamBean.ResBean.DeliveryTypeBean> deliveryTypeList;

	/**
	 * id : 0
	 * value : 余额
	 */


	private void initViewData() {
		addToList = addGoodsParamBean.getRes().getAddTo();
		isPortedList = addGoodsParamBean.getRes().getIsPorted();
		payTypeList = addGoodsParamBean.getRes().getPayType();
		publishTypeList = addGoodsParamBean.getRes().getInvitePublishType();
		deliveryTypeList = addGoodsParamBean.getRes().getDeliveryType();

		//是否拆分出售默认值
		tvReleaseTenderIssplit.setText(isPortedList.get(0).getValue());
		if (isPortedList.get(0).getId() == 0) {//不可拆分
			llReleaseTenderLeastNumber.setVisibility(View.GONE);
			etReleaseTenderLeastNumber.setText("0");
		} else {
			llReleaseTenderLeastNumber.setVisibility(View.VISIBLE);
		}
		addInviteOneSubmitBean.setIsPorted(isPortedList.get(0).getId() + "");
		//支付方式默认值
		tvReleasePaytype.setText(payTypeList.get(0).getValue());
		switch (payTypeList.get(0).getId()) {
			case 1://全款
				//隐藏分期ui
				llReleaseTenderPaytypeForInstallment.setVisibility(View.GONE);
				//设置分期的textview的值
				etScaleOne.setText("100");
				etScaleTwo.setText("0");
				etScaleThree.setText("0");
				break;
			case 2://分期
				//显示分期ui
				llReleaseTenderPaytypeForInstallment.setVisibility(View.VISIBLE);
				//设置分期的textview的值
				etScaleOne.setText("0");
				etScaleTwo.setText("0");
				etScaleThree.setText("0");
				break;
			case 3://货到付款
				//隐藏分期ui
				llReleaseTenderPaytypeForInstallment.setVisibility(View.GONE);
				//设置分期的textview的值
				etScaleOne.setText("0");
				etScaleTwo.setText("0");
				etScaleThree.setText("100");
				break;
		}

		addInviteOneSubmitBean.setPayType(payTypeList.get(0).getId() + "");
		//挂单方式默认值
		tvReleaseTenderPublishType.setText(publishTypeList.get(0).getValue());
		switch (publishTypeList.get(0).getId()) {
			case 2://2保证金挂单
				rlReleaseTenderSellMargin.setVisibility(View.VISIBLE);
				rlReleaseTenderSellCredit.setVisibility(View.GONE);
				break;
			case 3://3信誉挂单
				rlReleaseTenderSellMargin.setVisibility(View.GONE);
				rlReleaseTenderSellCredit.setVisibility(View.VISIBLE);
				break;
		}

		addInviteOneSubmitBean.setPublishType(publishTypeList.get(0).getId() + "");
		//交割方式默认值
		tvReleaseTenderDeliveryType.setText(deliveryTypeList.get(0).getValue());
		addInviteOneSubmitBean.setDeliveryType(deliveryTypeList.get(0).getId() + "");

		//初始化滚轮的值
  /*        oneModelListForGoodsPushType //发布类型滚轮一级
		  oneModelListForGoodsIssplit  //是否拆分滚轮一级
       oneModelListForGoodsPaytype  //支付方式滚轮一级
         oneModelListForGoodsPublishType //挂单方式滚轮一级
         oneModelListForGoodsDeliveryType//交割方式滚轮一级*/

		for (int i = 0; i < addToList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(addToList.get(i).getId() + "");
			oneModel.setName(addToList.get(i).getValue());
			oneModelListForGoodsPushType.add(oneModel);
		}
		for (int i = 0; i < isPortedList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(isPortedList.get(i).getId() + "");
			oneModel.setName(isPortedList.get(i).getValue());
			oneModelListForGoodsIssplit.add(oneModel);
		}
		for (int i = 0; i < payTypeList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(payTypeList.get(i).getId() + "");
			oneModel.setName(payTypeList.get(i).getValue());
			oneModelListForGoodsPaytype.add(oneModel);
		}
		for (int i = 0; i < publishTypeList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(publishTypeList.get(i).getId() + "");
			oneModel.setName(publishTypeList.get(i).getValue());
			oneModelListForGoodsPublishType.add(oneModel);
		}
		for (int i = 0; i < deliveryTypeList.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(deliveryTypeList.get(i).getId() + "");
			oneModel.setName(deliveryTypeList.get(i).getValue());
			oneModelListForGoodsDeliveryType.add(oneModel);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.title_left_img:
				finish();
				break;
			case R.id.title_right_tv://下一步
				if (releaseInviteState == 1) {//发布招标进入的
					nextStep();
				} else if (releaseInviteState == 2) {//返回进入的

				} else if (releaseInviteState == 3) {//招标详情进入的
					nextStepForDetail();
				}

				break;
			case R.id.rl_release_tender_classify://商品分类
				chooseClassify();
				break;
			case R.id.rl_release_tender_issplit://是否拆分
				showPop(oneModelListForGoodsIssplit, rlReleaseTenderIssplit, 1);
				break;
			case R.id.rl_release_tender_paytype://支付方式
				showPop(oneModelListForGoodsPaytype, rlReleaseTenderPaytype, 1);
				break;
			case R.id.rl_release_tender_publish_type://挂单方式
				showPop(oneModelListForGoodsPublishType, rlReleaseTenderPublishType, 1);
				break;
			case R.id.rl_release_tender_delivery_type://交割方式
				showPop(oneModelListForGoodsDeliveryType, rlReleaseTenderDeliveryType, 1);
				break;
			case R.id.rl_release_tender_delivery_area://交割地（所在地）
				chooseDeliveryArea();
				break;
			case R.id.rl_release_tender_start_time://开始时间
				showTimePop("选择开始时间", rlReleaseTenderStartTime);
				break;
			case R.id.rl_release_tender_end_time://结束时间
				showTimePop("选择结束时间", rlReleaseTenderEndTime);
				break;
			default:
				break;
		}
	}

	private void nextStepForDetail() {
		//跳转到附加信息 传分类id 和 addto
		Intent intent = new Intent();
		intent.setClass(ReleaseTenderActivity.this, AddInviteTwoActivity.class);

		intent.putExtra("catId", catId);
		intent.putExtra("inviteId", inviteId);
		intent.putExtra("releaseInviteState", releaseInviteState);
		intent.putExtra("inviteStatus", inviteStatus);
		Utils.showLog("===重新编辑的时候提交的releaseInviteState：" + releaseInviteState);
		startActivityForResult(intent, STEP_TWO_REQUEST_CODE);


	}


	final List<OneModel> oneModelListForGoodsClassify = new ArrayList<OneModel>();//商品分类滚轮一级
	final List<OneModel> oneModelListForGoodsPushType = new ArrayList<OneModel>();//发布类型滚轮一级 addto
	final List<OneModel> oneModelListForGoodsIssplit = new ArrayList<OneModel>();//是否拆分滚轮一级
	final List<OneModel> oneModelListForGoodsPaytype = new ArrayList<OneModel>();//支付方式滚轮一级
	final List<OneModel> oneModelListForGoodsPublishType = new ArrayList<OneModel>();//挂单方式滚轮一级
	final List<OneModel> oneModelListForGoodsDeliveryType = new ArrayList<OneModel>();//交割方式滚轮一级
	final List<OneModel> oneModelListForDeliveryArea = new ArrayList<OneModel>();//交割地滚轮一级

	/**
	 * 交割地（所在地）
	 */
	private void chooseDeliveryArea() {
		//区域
		if (ConstantClass.areaBean == null) {
			AreaSubmitBean areaSubmitBean = new AreaSubmitBean("recursion");
			new AreaBeanModel(this, new OnNetBackListener<AreaBean>() {
				@Override
				public void netBack(AreaBean data) {
					if (data == null) {

					} else {
						if (data.getStatus() == 1) {

							initAreaData(data);
							ConstantClass.areaBean = data;
						} else {
							Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request(JSONUtil.toJSON(areaSubmitBean), true);
		} else {
			//已经有不请求网络
			initAreaData(ConstantClass.areaBean);
		}
	}

	/**
	 * 拆分地区分类数据
	 *
	 * @param data
	 */
	private void initAreaData(AreaBean data) {
		oneModelListForDeliveryArea.clear();
		//一级
		List<AreaBean.ResBean> res = data.getRes();//原始数据
		Utils.showLog("==============res.size=" + res.size());
		for (int i = 0; i < res.size(); i++) {
			OneModel oneModel = new OneModel();
			oneModel.setId(res.get(i).getId());
			oneModel.setName(res.get(i).getName());

			//  二级
			List<TwoModel> twoModelList2 = new ArrayList<TwoModel>();//滚轮二级
			for (int j = 0; j < res.get(i).getChild().size(); j++) {

				TwoModel twoModel = new TwoModel();
				twoModel.setId(res.get(i).getChild().get(j).getId());
				twoModel.setName(res.get(i).getChild().get(j).getName());

				List<ThreeModel> threeModelList3 = new ArrayList<ThreeModel>();//滚轮三级
				for (int h = 0; h < res.get(i).getChild().get(j).getChild().size(); h++) {
					ThreeModel threeModel = new ThreeModel();
					threeModel.setId(res.get(i).getChild().get(j).getChild().get(h).getId());
					threeModel.setName(res.get(i).getChild().get(j).getChild().get(h).getName());
					threeModelList3.add(threeModel);

					twoModel.setThreeModelList(threeModelList3);

				}
				twoModelList2.add(twoModel);
			}
			oneModel.setTwoModelList(twoModelList2);
			oneModelListForDeliveryArea.add(oneModel);
		}
		showPop(oneModelListForDeliveryArea, rlReleaseTenderDeliveryArea, 3);
	}

	GoodsCategoryBeanTest goodsCategoryBeanTest;//获取的分类的集合

	/**
	 * 获取分类
	 */
	private void chooseClassify() {
		//测试gson以及三级滚轮赋值
		GoodsCategorySubmitBean goodsCategorySubmitBean = new GoodsCategorySubmitBean();
		goodsCategorySubmitBean.setLevel("level");
		goodsCategorySubmitBean.setKey("no");

		new GoodsCategoryModelTest(this, new OnNetBackListener<GoodsCategoryBeanTest>() {
			@Override
			public void netBack(GoodsCategoryBeanTest data) {
				if (data == null) {

				} else {
					if (data.getStatus().equals("1")) {
						goodsCategoryBeanTest = data;
						oneModelListForGoodsClassify.clear();
						//一级
						List<GoodsCategoryBeanTest.ResBean> res = data.getRes();//原始数据

						Utils.showLog("==============res.size=" + res.size());
						for (int i = 0; i < res.size(); i++) {
							OneModel oneModel = new OneModel();
							oneModel.setId(res.get(i).getId());
							oneModel.setName(res.get(i).getName());

							//  二级
							List<TwoModel> twoModelList2 = new ArrayList<TwoModel>();//滚轮二级
							for (int j = 0; j < res.get(i).getChildren().size(); j++) {

								TwoModel twoModel = new TwoModel();
								twoModel.setId(res.get(i).getChildren().get(j).getId());
								twoModel.setName(res.get(i).getChildren().get(j).getName());

								List<ThreeModel> threeModelList3 = new ArrayList<ThreeModel>();//滚轮三级
								for (int h = 0; h < res.get(i).getChildren().get(j).getChildren().size(); h++) {
									ThreeModel threeModel = new ThreeModel();
									threeModel.setId(res.get(i).getChildren().get(j).getChildren().get(h).getId());
									threeModel.setName(res.get(i).getChildren().get(j).getChildren().get(h).getName());
									threeModelList3.add(threeModel);

									twoModel.setThreeModelList(threeModelList3);

								}
								twoModelList2.add(twoModel);
							}
							oneModel.setTwoModelList(twoModelList2);
							oneModelListForGoodsClassify.add(oneModel);
						}
						showPop(oneModelListForGoodsClassify, rlReleaseTenderClassify, 3);
					} else {
						Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			}
		}).request(JSONUtil.toJSON(goodsCategorySubmitBean), true);
	}

	SkmModiPopup skmModiPopup;

	private void showPop(List<OneModel> oneModelList, View view, int level) {
		skmModiPopup = new SkmModiPopup(this, skmPopOnClickListener, oneModelList, "选择", level, view);
		skmModiPopup.showAtLocation(findViewById(R.id.rl_release_tender),
				Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
	}

	public SkmDatePickerPopup skmDatePickerPopup;

	private void showTimePop(String content, View view) {
		//skmDatePickerPopup = new SkmDatePickerPopup(this, skmDatePickerPopupOnClickListener, content, view);
		boolean isShouledChangeDate = false;
		long targetDate;
		if ("".equals(addInviteOneSubmitBean.getStartTime())||addInviteOneSubmitBean.getStartTime()==null){//开始时间没有选择 在当前时间添加15天
			isShouledChangeDate = true;
			Date date=new Date();//取时间
			Calendar calendar   = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(calendar.DATE,15);//把日期往后增加一天.整数往后推,负数往前移动
			targetDate=calendar.getTimeInMillis();
		}else {//开始时间有选择 在开始时间添加15天
			isShouledChangeDate = true;
			long startTime =  Long.parseLong(addInviteOneSubmitBean.getStartTime()+"000");
			Date date=new Date(startTime);//取时间
			Calendar calendar   = Calendar.getInstance();
			calendar.setTime(date);
			calendar.add(calendar.DATE,15);//把日期往后增加一天.整数往后推,负数往前移动
			targetDate=calendar.getTimeInMillis();
		}
		//如果点击的是开始菜单 则时间默认
		if (view.getId()==R.id.rl_release_tender_start_time){
			isShouledChangeDate = false;
		}

		skmDatePickerPopup = new SkmDatePickerPopup(this, skmDatePickerPopupOnClickListener, content, view,isShouledChangeDate,targetDate);

		skmDatePickerPopup.showAtLocation(findViewById(R.id.rl_release_tender),
				Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
	}

	public SkmDatePickerPopup.SkmDatePickerPopupOnClickListener skmDatePickerPopupOnClickListener = new SkmDatePickerPopup.SkmDatePickerPopupOnClickListener() {

		@Override
		public void myOnClick(int year, int month, int day, int hour, int minute, View v, View root) {
			skmDatePickerPopup.dismiss();
		  /*  Toast.makeText(ReleaseTenderActivity.this, "您选择的日期：" + year + "年  "
					+ month + "月  " + day + "日" + hour + "时 " + minute + "分钟", Toast.LENGTH_SHORT).show();*/
			String time = year + "-" + month + "-" + day + " " + hour + ":" + minute;
			Utils.showLog("============时间" + TimeUtil.timeToTimeStampForSecond(time, TimeUtil.fotmatString2));
			switch (root.getId()) {
				case R.id.rl_release_tender_start_time://开始时间
					tvReleaseTenderStartTime.setText(time);
					//保存开始时间的值
					addInviteOneSubmitBean.setStartTime(TimeUtil.timeToTimeStampForSecond(time, TimeUtil.fotmatString2));
					break;
				case R.id.rl_release_tender_end_time://结束时间
					tvReleaseTenderEndTime.setText(time);
					//保存结束时间的值
					addInviteOneSubmitBean.setEndTime(TimeUtil.timeToTimeStampForSecond(time, TimeUtil.fotmatString2));
					break;

			}
		}

	};
	public SkmModiPopup.SkmPopOnClickListener skmPopOnClickListener = new SkmModiPopup.SkmPopOnClickListener() {

		@Override
		public void myOnClick(int pOneCurrent, int pTwoCurrent, int pThreeCurrent, View v, View root) {
			skmModiPopup.dismiss();
			switch (root.getId()) {
				case R.id.rl_release_tender_classify://点击商品分类的处理
					//Toast.makeText(ReleaseTenderActivity.this, "一级：id:" + oneModelList.get(pOneCurrent).getId() + " name:" + oneModelList.get(pOneCurrent).getName()+
					// " 二级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getName() + "
					// 三级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName() , Toast.LENGTH_SHORT).show();
					//回显选中的第三项的值
					tvReleaseTenderClassify.setText(oneModelListForGoodsClassify.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName() + "");

					String catIdOne = oneModelListForGoodsClassify.get(pOneCurrent).getId();
					String catIdTwo = oneModelListForGoodsClassify.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId();
				   /* if("8888".equals(catIdTwo)){//二级为空 那么三级也为空 id取第一个  未加判断一般没事
					}*/
					//选中的分类id 这里分类指的是第三个
					String catIdThree = oneModelListForGoodsClassify.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId();
					//保存选中的分类id的值 这里分类指的是第三个
					addInviteOneSubmitBean.setCatId(catIdThree);
					//根据分类设置单位 这里分类指的是第三个
					goodsUnit = goodsCategoryBeanTest.getRes().get(pOneCurrent).getChildren().get(pTwoCurrent).getChildren().get(pThreeCurrent).getUnit();
					tvReleaseTenderUnit.setText("(" + goodsUnit + ")：");
					tvReleaseTenderLeastNumberUnit.setText("(" + goodsUnit + "):");

					break;

				case R.id.rl_release_tender_issplit://是否拆分 0否 1是 如果是否 则隐藏最小供应量 且设置值为0
					tvReleaseTenderIssplit.setText(oneModelListForGoodsIssplit.get(pOneCurrent).getName() + "");

					if ("0".equals(oneModelListForGoodsIssplit.get(pOneCurrent).getId())) {//不可拆分
						llReleaseTenderLeastNumber.setVisibility(View.GONE);
						etReleaseTenderLeastNumber.setText("0");
					} else {
						llReleaseTenderLeastNumber.setVisibility(View.VISIBLE);
					}
					//保存是否拆分的值
					addInviteOneSubmitBean.setIsPorted(oneModelListForGoodsIssplit.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_tender_paytype://支付方式 1全款（100，0，0） 2分期 3货到付款（0，0，100）  分期显示分期ui,其余的隐藏   "payScale": "20,50,30",
					tvReleasePaytype.setText(oneModelListForGoodsPaytype.get(pOneCurrent).getName() + "");

					switch (Integer.parseInt(oneModelListForGoodsPaytype.get(pOneCurrent).getId())) {
						case 1://全款
							//隐藏分期ui
							llReleaseTenderPaytypeForInstallment.setVisibility(View.GONE);
							//设置分期的textview的值
							etScaleOne.setText("100");
							etScaleTwo.setText("0");
							etScaleThree.setText("0");
							break;
						case 2://分期
							//显示分期ui
							llReleaseTenderPaytypeForInstallment.setVisibility(View.VISIBLE);
							//设置分期的textview的值
							etScaleOne.setText("0");
							etScaleTwo.setText("0");
							etScaleThree.setText("0");
							break;
						case 3://货到付款
							//隐藏分期ui
							llReleaseTenderPaytypeForInstallment.setVisibility(View.GONE);
							//设置分期的textview的值
							etScaleOne.setText("0");
							etScaleTwo.setText("0");
							etScaleThree.setText("100");
							break;
					}

					//保存支付方式的值
					addInviteOneSubmitBean.setPayType(oneModelListForGoodsPaytype.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_tender_publish_type://挂单方式 1仓单挂单 2保证金挂单 3信誉挂单
					tvReleaseTenderPublishType.setText(oneModelListForGoodsPublishType.get(pOneCurrent).getName() + "");
					switch (Integer.parseInt(oneModelListForGoodsPublishType.get(pOneCurrent).getId())) {
						case 2://2保证金挂单
							rlReleaseTenderSellMargin.setVisibility(View.VISIBLE);
							rlReleaseTenderSellCredit.setVisibility(View.GONE);
							//计算保证金
							// calculateMargin();

							break;
						case 3://3信誉挂单
							rlReleaseTenderSellMargin.setVisibility(View.GONE);
							rlReleaseTenderSellCredit.setVisibility(View.VISIBLE);
							//计算信誉值
							calculateCredit();
							break;
					}
					//保存挂单方式的值
					addInviteOneSubmitBean.setPublishType(oneModelListForGoodsPublishType.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_tender_delivery_type://交割方式
					tvReleaseTenderDeliveryType.setText(oneModelListForGoodsDeliveryType.get(pOneCurrent).getName() + "");
					//保存交割方式的值
					addInviteOneSubmitBean.setDeliveryType(oneModelListForGoodsDeliveryType.get(pOneCurrent).getId());
					break;
				case R.id.rl_release_tender_delivery_area://交割地
                       /* "deliveryArea": "山东省青岛市市南区",
                        "province": "28",
                        "city": "128",
                        "county": "512",*/
					//Toast.makeText(ReleaseTenderActivity.this, "一级：id:" + oneModelList.get(pOneCurrent).getId() + " name:" + oneModelList.get(pOneCurrent).getName()+ " 二级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getName() + " 三级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName() , Toast.LENGTH_SHORT).show();
					String deliveryArea = oneModelListForDeliveryArea.get(pOneCurrent).getName() + oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getName() + oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName();
					String province = oneModelListForDeliveryArea.get(pOneCurrent).getId();
					String city = oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId();
					String county = oneModelListForDeliveryArea.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId();

					tvReleaseTenderDeliveryArea.setText(deliveryArea);
					//保存交割地信息的值
					addInviteOneSubmitBean.setDeliveryArea(deliveryArea);
					addInviteOneSubmitBean.setProvince(province);
					addInviteOneSubmitBean.setCity(city);
					addInviteOneSubmitBean.setCounty(county);

					break;
				default:
					break;
			}

		}
	};

	/**
	 * 计算信誉值
	 */
	private void calculateCredit() {


	}

	/**
	 * 计算保证金信誉值 需要总价 针对不同的发布类型判断
	 */
	private void calculateMarginAndCredit() {
		//计算的type type: goods | invite | auction  保证金挂单 商城 招标 拍卖
		String type = "invite";
		double money = 0;
		goodsNumber = etReleaseTenderNumber.getText().toString();//数量
		goodsPrice = etReleaseTenderPrice.getText().toString();//单价
		if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber) && !TextUtils.isEmpty(goodsPrice) && Utils.isNum(goodsPrice)) {

			money = Double.parseDouble(goodsNumber) * Double.parseDouble(goodsPrice);
			Utils.showLog("=====招标 money:" + money);
		}

		Utils.showLog("====goodsNumber:" + goodsNumber + " goodsPrice:" + goodsPrice + " money:" + money + "   goodsTotalPrice:" + goodsTotalPrice);

		if (money > 0) {
			// 保证金 "role":"","type":"","money":"10000","objId":""}
			CalculateMarginSubmitBean calculateMarginSubmitBean = new CalculateMarginSubmitBean();
			calculateMarginSubmitBean.setRole("buyer");
			calculateMarginSubmitBean.setType(type);
			calculateMarginSubmitBean.setMoney(money + "");
			calculateMarginSubmitBean.setObjId("");

			new CalculateMarginModel(this, new OnNetBackListener<CalculateMarginBean>() {
				@Override
				public void netBack(CalculateMarginBean data) {
					if (data == null) {
						Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							tvCash.setText(data.getRes().getCash());
							tvMargin.setText(data.getRes().getMargin());
						} else {
							Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request(JSONUtil.toJSON(calculateMarginSubmitBean), false);

			//	[42]信誉挂单信誉值计算 {"role":" ","type":" ","money":"10000"}
			CalculateCreditSubmitBean calculateCreditSubmitBean = new CalculateCreditSubmitBean();
			calculateCreditSubmitBean.setRole("buyer");
			calculateCreditSubmitBean.setType(type);
			calculateCreditSubmitBean.setMoney(money + "");

			new CalculateCreditModel(this, new OnNetBackListener<CalculateCreditBean>() {
				@Override
				public void netBack(CalculateCreditBean data) {
					if (data == null) {
						Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						if (data.getStatus() == 1) {
							tvCredit.setText(data.getRes().getCredit());
							tvOwncredit.setText(data.getRes().getOwnCredit());
						} else {
							Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
						}
					}
				}
			}).request(JSONUtil.toJSON(calculateCreditSubmitBean), false);


		}

	}

	//下一步
	int addTo = 0;

	private boolean checkData() {
		if (tvReleaseTenderClassify.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择分类", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (etReleaseTenderTitle.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写招标名称", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (etReleaseTenderPrice.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写单价", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (etReleaseTenderNumber.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写数量", Toast.LENGTH_SHORT).show();
			return false;
		}
		//最小供应量 etReleaseTenderLeastNumber;
		if (etReleaseTenderMarginScale.getText().toString().length() == 0) {
			Toast.makeText(this, "请填写投标保证金比例", Toast.LENGTH_SHORT).show();
			return false;
		}

		//分期 etScaleOne; etScaleTwo; etScaleThree;
		//交割地
		if (tvReleaseTenderDeliveryArea.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择所在地", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (tvReleaseTenderDeliveryType.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择交割方式", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (tvReleaseTenderStartTime.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择开始时间", Toast.LENGTH_SHORT).show();
			return false;
		}
		if (tvReleaseTenderEndTime.getText().toString().length() == 0) {
			Toast.makeText(this, "请选择结束时间", Toast.LENGTH_SHORT).show();
			return false;
		}
		if ((Long.parseLong(addInviteOneSubmitBean.getStartTime())-Long.parseLong(addInviteOneSubmitBean.getEndTime()))>=0){
			Toast.makeText(this, "结束时间应该晚于开始时间", Toast.LENGTH_SHORT).show();
			return false;
		}
		return true;
	}

	private void nextStep() {
		if (!checkData()) {
			return;
		}

     /*   {
            "catId":"2", "title":"标准精煤100T", "productCode":"山西高能牌", "number":"100.000", "addFrom":
            "0", "addTo":"0", "price":"358.00", "totalPrice":"35800.00", "sellMargin":
            "7160.00", "buyMargin":"0.00", "creditNum":"0", "isPorted":"1", "leastNumber":
            "10.000", "leastAdd":"0", "fixedPrice":"0", "stepPrice":"36,37,38", "payType":
            "2", "payScale":"20,50,30", "publishType":"2", "storePic":"", "toUser":
            "8", "deliveryArea":"山东省青岛市市南区", "province":"28", "city":"128", "county":
            "512", "deliveryType":"1", "startTime":"1470277254", "endTime":"1470286254", "remark":
            "这里是商品备注"
        }*/
		addInviteOneSubmitBean.setTitle(etReleaseTenderTitle.getText().toString());
		addInviteOneSubmitBean.setProductCode(etReleaseTenderProductCode.getText().toString());
		addInviteOneSubmitBean.setNumber(etReleaseTenderNumber.getText().toString());
		addInviteOneSubmitBean.setPrice(TextUtils.isEmpty(etReleaseTenderPrice.getText().toString()) ? "0" : etReleaseTenderPrice.getText().toString());

		//以下用于计算totalPrice

		double goodsTotalPriceDouble = 0;
		goodsNumber = etReleaseTenderNumber.getText().toString();//数量
		goodsPrice = etReleaseTenderPrice.getText().toString();//单价
		if (!TextUtils.isEmpty(goodsNumber) && Utils.isNum(goodsNumber) && !TextUtils.isEmpty(goodsPrice) && Utils.isNum(goodsPrice)) {

			goodsTotalPriceDouble = Double.parseDouble(goodsNumber) * Double.parseDouble(goodsPrice);
			Utils.showLog("=====   TotalPriceDouble:" + goodsTotalPriceDouble);

		}

		addInviteOneSubmitBean.setTotalPrice(goodsTotalPriceDouble + "");

		//招标不需要 addInviteOneSubmitBean.setSellMargin(TextUtils.isEmpty(tv_margin.getText().toString())?"0":tv_margin.getText().toString());//卖家保证金
		//addInviteOneSubmitBean.setBuyMargin(TextUtils.isEmpty(etReleaseTenderBuyMargin.getText().toString())?"0":etReleaseTenderBuyMargin.getText().toString());     //buyMargin 买家要交的保证金


		//挂单方式 1仓单挂单 2保证金挂单 3信誉挂单

		switch (Integer.parseInt(addInviteOneSubmitBean.getPublishType())) {
			case 1://1仓单挂单
				addInviteOneSubmitBean.setCredit("0.000");//信誉 信誉挂单所需信誉,谁发布商品就扣谁的
				addInviteOneSubmitBean.setBuyMargin("0.00");
				break;
			case 2://2保证金挂单
				addInviteOneSubmitBean.setCredit("0.000");//信誉 信誉挂单所需信誉,谁发布商品就扣谁的
				addInviteOneSubmitBean.setBuyMargin(TextUtils.isEmpty(tvMargin.getText().toString()) ? "0" : (Utils.roundForNumber(tvMargin.getText().toString(),2)));     //buyMargin 买家要交的保证金
				break;
			case 3://3信誉挂单
				addInviteOneSubmitBean.setCredit(Utils.roundForNumber(tvCredit.getText().toString(),3));//信誉 信誉挂单所需信誉,谁发布商品就扣谁的
				addInviteOneSubmitBean.setBuyMargin("0.00");
				break;
		}


		//isPorted

		if ("0".equals(addInviteOneSubmitBean.getIsPorted())) {//不拆分 最小供应量等于总量
			addInviteOneSubmitBean.setLeastNumber(etReleaseTenderNumber.getText().toString());

		} else {
			addInviteOneSubmitBean.setLeastNumber(etReleaseTenderLeastNumber.getText().toString());
		}


		//招标不需要addInviteOneSubmitBean.setLeastAdd(etReleaseTenderLeastAdd.getText().toString());
		//招标不需要addInviteOneSubmitBean.setFixedPrice(TextUtils.isEmpty(etReleaseTenderFixedPrice.getText().toString())?"0":etReleaseTenderFixedPrice.getText().toString());
		//stepPrice
		//payType 支付方式 1全款 2分期 3货到付款
		String payScale = "";
		if ("1".equals(addInviteOneSubmitBean.getPayType())) {
			payScale = "100,0,0";
		} else if ("2".equals(addInviteOneSubmitBean.getPayType())) {
			payScale = etScaleOne.getText().toString() + "," + etScaleTwo.getText().toString() + "," + etScaleThree.getText().toString();
		} else if ("3".equals(addInviteOneSubmitBean.getPayType())) {
			payScale = "0,0,100";
		}
		addInviteOneSubmitBean.setPayScale(payScale);
		//publishType
		// addInviteOneSubmitBean.setStorePic();
		//招标不需要addInviteOneSubmitBean.setToUser("0");//不是定向单都为0 这里要修改
		//deliveryArea
		//province
		//city
		//county
		//deliveryType
		//startTime
		//endTime
		addInviteOneSubmitBean.setRemark(etReleaseTenderRemark.getText().toString());

		addInviteOneSubmitBean.setMarginScale(etReleaseTenderMarginScale.getText().toString());

		//如果是保证金或者信誉挂单，弹出付款信誉界面   2保证金 3信誉
		if (2 == Integer.parseInt(addInviteOneSubmitBean.getPublishType())||3 == Integer.parseInt(addInviteOneSubmitBean.getPublishType())) {
			Intent intentPay = getIntent();
			intentPay.setClass(this, PayForReleaseGoodsActivity.class);
			intentPay.putExtra("publishType", Integer.parseInt(addInviteOneSubmitBean.getPublishType()));
			//保证金的
			intentPay.putExtra("geld", tvMargin.getText().toString());
			intentPay.putExtra("balance", tvCash.getText().toString());
			//信誉的
			intentPay.putExtra("credit", tvCredit.getText().toString());
			intentPay.putExtra("ownCredit", tvOwncredit.getText().toString());
			startActivityForResult(intentPay, PAY_REQUEST_CODE);
		} else {
			addGoodsStepOneSubmit();
		}

	}

	private void addGoodsStepOneSubmit() {
		addInviteOneSubmitBean.setPayPassword(payPassword);
		new AddInviteOneModel(this, new OnNetBackListener<AddInviteOneBean>() {
			@Override
			public void netBack(AddInviteOneBean data) {
				if (data == null) {
					Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
				} else {
					if (data.getStatus() == 1) {

						//跳转到附加信息 传分类id 和 addto
						Intent intent = new Intent();
						intent.setClass(ReleaseTenderActivity.this, AddInviteTwoActivity.class);

						intent.putExtra("catId", addInviteOneSubmitBean.getCatId());
						intent.putExtra("inviteId", data.getRes().getInvite_id());

						releaseInviteState = 3;//提交后状态需要变化了
						intent.putExtra("releaseInviteState", releaseInviteState);
						intent.putExtra("inviteStatus", inviteStatus);
						Utils.showLog("===初次编辑的时候提交的releaseInviteState：" + releaseInviteState);
						startActivityForResult(intent, STEP_TWO_REQUEST_CODE);


						Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					} else {
						Toast.makeText(ReleaseTenderActivity.this, data.getMsg(), Toast.LENGTH_SHORT).show();
					}
				}
			}
		}).request(JSONUtil.toJSON(addInviteOneSubmitBean), true);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		Utils.showLog("=======requestCode=" + requestCode);
		switch (requestCode) {
			case PAY_REQUEST_CODE://是付款返回的
				if (resultCode == PAY_RESULT_CODE) {//正常付款返回的
					payPassword=data.getStringExtra("payPassword");
					addGoodsStepOneSubmit();
				}
				break;
			case STEP_TWO_REQUEST_CODE: //是第二步返回的
				if (resultCode == STEP_TWO_RESULT_CODE) {
					catId = data.getStringExtra("catId");
					inviteId = data.getStringExtra("inviteId");
					releaseInviteState = data.getIntExtra("releaseInviteState", 1);
					//这里状态是3 需要  Id


					Utils.showLog("====返回的releaseInviteState：" + releaseInviteState);
					initView();
					initListener();
					init();
				}
				break;
		}
	}

}
